import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:wheel_of_fortune/model/address_model.dart';
import 'package:wheel_of_fortune/provider/address_provider.dart';
import 'package:wheel_of_fortune/utils/utils.dart';

class DropdownWidget extends StatefulWidget {
  final List dataList;
  final List<DropdownMenuItem> items;
  final type; // city or province or region
  final onChanged;
  const DropdownWidget(
      {this.dataList,
      this.items,
      this.type = 'region',
      this.onChanged,
      Key key})
      : super(key: key);

  @override
  _DropdownWidgetState createState() => _DropdownWidgetState();
}

class _DropdownWidgetState extends State<DropdownWidget> {
  var dropdownValue;

  @override
  Widget build(BuildContext context) {
    print(widget.items);
    return Container(
      child: Container(
        height: 25,
        decoration: BoxDecoration(
          color: whiteColor,
          borderRadius: BorderRadius.all(Radius.circular(4.0)),
          border: Border.all(
            color: greyDBColor,
            width: 0.5,
          ),
          boxShadow: [
            BoxShadow(
                color: Color.fromARGB(255, 240, 240, 240),
                offset: Offset(2.0, 2.0),
                blurRadius: 10.0,
                spreadRadius: 0.0),
            BoxShadow(color: Colors.white12, offset: Offset(1.0, 1.0)),
            BoxShadow(color: Colors.white)
          ],
        ),
        child: DropdownButtonHideUnderline(
          child: DropdownButton(
            isExpanded: true,
            style: TextStyle(fontSize: 12, color: Colors.black),
            items: [],
            hint: Padding(
              padding: EdgeInsets.only(left: 10),
              child: Text(
                widget.type == 'city'
                    ? 'City'
                    : (widget.type == 'region' ? 'Region' : 'Province'),
                style: TextStyle(fontSize: 12, color: Colors.black),
              ),
            ),
            value: dropdownValue,
            onChanged: (value) {
              setState(() {
                dropdownValue = value;
                if (widget.onChanged != null) {
                  widget.onChanged(value);
                }
              });
            },
          ),
        ),
      ),
    );
  }
}

/**
 * 
    List.generate(widget.dataList.length, (index) {
              final item = widget.dataList[index];
              if (widget.type == 'city') {
                return DropdownMenuItem(
                  child: Padding(
                    padding: EdgeInsets.only(left: 10),
                    child: Text('   ${(item as CityModel).cityName}'),
                  ),
                  value: item,
                );
              } else if (widget.type == 'region') {
                return DropdownMenuItem(
                  child: Padding(
                    padding: EdgeInsets.only(left: 10),
                    child: Text('   ${(item as RegionModel).regionName}'),
                  ),
                  value: item,
                );
              } else {
                return DropdownMenuItem(
                  child: Text('   ${(item as ProvinceModel).provinceName}'),
                  value: item,
                );
              }
            })
 */
